<?php
	//include("../connect/connect_dsccmis.php");
	$sql="select count(*) as c 
 from mis_viewlosofper t1 inner join dscc.TempEventAndCaseOfEvent t2 on t1.evnid=t2.evnid   where t1.evndte >= '25470104' and persiden is not null and persiden <> ''
 and cdscc in ('1','2')";
	$rs=mysql_query($sql);
	$row=mysql_fetch_array($rs);
	$nU=$row[0];
	
	$sql="select count(*) as c from 
(select persiden 
 from mis_viewlosofper t1 inner join dscc.TempEventAndCaseOfEvent t2 on t1.evnid=t2.evnid   where t1.evndte >= '25470104' and persiden is not null and persiden <> ''
 and cdscc in ('1','2')) t1 inner join 
(select pid from dscc.rev_opmhelp where rev_all_amount > 0) t2 on t1.persiden=t2.pid";
	$rs=mysql_query($sql);
	$row=mysql_fetch_array($rs);
	$nA=$row[0];
	
	$sql="select count(*) as c from 
(select persiden 
 from mis_viewlosofper t1 inner join dscc.TempEventAndCaseOfEvent t2 on t1.evnid=t2.evnid   where t1.evndte >= '25470104' and persiden is not null and persiden <> ''
 and cdscc in ('1','2')) t1 inner join 
(select victim_idcardno from dscc.rev_vmsmentalhelp where visitdate <> '') t2 on t1.persiden=t2.victim_idcardno";
	$rs=mysql_query($sql);
	$row=mysql_fetch_array($rs);
	$nB=$row[0];
	
	$sql="select count(*) as c from 
(select persiden 
 from mis_viewlosofper t1 inner join dscc.TempEventAndCaseOfEvent t2 on t1.evnid=t2.evnid   where t1.evndte >= '25470104' and persiden is not null and persiden <> ''
 and cdscc in ('1','2')) t1 inner join 
(select victim_idcardno from dscc.rev_vmsmentalhelp where visitdate <> '') t2 on t1.persiden=t2.victim_idcardno inner join
 (select pid from dscc.rev_opmhelp where rev_all_amount > 0) t3 on t1.persiden=t3.pid";
	$rs=mysql_query($sql);
	$row=mysql_fetch_array($rs);
	$nAB=$row[0];
	
	//วันที่ปัจจุบัน
	$tempY=date("Y");
	if($tempY<"2550"){
		$tempY=(int)$tempY+543;
	}
	$date_cal= $tempY.date("md");
	$datetime_cal= $tempY.date("-m-d-H:i");
	
	$sql = "insert into mis_relief_coverage(nu,na,nb,nab,caldate,caldatetime) values($nU,$nA,$nB,$nAB,'$date_cal','$datetime_cal');";
	$rs=mysql_query($sql);
	//mysql_close($c);
	echo "<br>complete append mis_relief_coverage on dsccmis";
?>